home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-10-26 | 4.2 KB | 153 lines | [TEXT/MPS ] |
- #
- # filecmds.test
- #
- # Tests for the copyfile, and pipe commands.
- #---------------------------------------------------------------------------
- # Copyright 1992-1993 Karl Lehenbauer and Mark Diekhans.
- #
- # Permission to use, copy, modify, and distribute this software and its
- # documentation for any purpose and without fee is hereby granted, provided
- # that the above copyright notice appear in all copies. Karl Lehenbauer and
- # Mark Diekhans make no representations about the suitability of this
- # software for any purpose. It is provided "as is" without express or
- # implied warranty.
- #------------------------------------------------------------------------------
- # $Id: filecmds.test,v 2.4 1993/08/18 05:23:56 markd Exp $
- #------------------------------------------------------------------------------
- #
-
- if {[info procs test] != "test"} then {source testlib.tcl}
-
- # Create a test file
-
- unlink -nocomplain {IOTEST.TMP IOTEST2.TMP IOTEST3.TMP}
-
- set testFH [open IOTEST.TMP w]
- set testFileSize 0
- for {set cnt 0} {$cnt < 100} {incr cnt} {
- set rec [GenRec $cnt]
- puts $testFH $rec
- incr testFileSize [expr [clength $rec]+1]
- }
- close $testFH
-
- if {$testFileSize != [file size IOTEST.TMP]} {
- error "Wrong file size calculated for IOTEST.TMP"
- }
-
- Test filecmds-3.1 {copyfile tests} {
- set testFH [open IOTEST.TMP r]
- set testFH2 [open IOTEST2.TMP w]
- copyfile $testFH $testFH2
- close $testFH
- close $testFH2
- system "diff IOTEST.TMP IOTEST2.TMP >/dev/null 2>&1"
- } 0 0
-
- Test filecmds-3.2 {copyfile tests} {
- set testFH [open IOTEST3.TMP w]
- set testFH2 [open IOTEST2.TMP w]
- set stat [list [catch {copyfile $testFH $testFH2} msg] \
- [lrange $msg 1 end]]
- close $testFH
- close $testFH2
- set stat
- } 0 {1 {wasn't opened for reading}}
-
- Test filecmds-3.3 {copyfile tests} {
- set testFH [open IOTEST.TMP r]
- set testFH2 [open IOTEST2.TMP r]
- set stat [list [catch {copyfile $testFH $testFH2} msg] \
- [lrange $msg 1 end]]
- close $testFH
- close $testFH2
- set stat
- } 0 {1 {wasn't opened for writing}}
-
- Test filecmds-3.4 {copyfile tests} {
- copyfile $testFH $testFH2
- } 1 "file \"$testFH\" isn't open"
-
- Test filecmds-3.5 {copyfile tests} {
- copyfile
- } 1 {wrong # args: copyfile ?-bytes num|-maxbytes num? fromFileId toFileId}
-
- foreach flag {-bytes -maxbytes} {
- Test filecmds-3.6.$flag {copyfile tests} {
- set copySize [expr ($testFileSize*2)/3]
- set testFH [open IOTEST.TMP r]
- set testFH2 [open IOTEST2.TMP w]
- copyfile $flag $copySize $testFH $testFH2
- close $testFH
- close $testFH2
-
- set testFH [open IOTEST.TMP r]
- set testData [read $testFH $copySize]
- close $testFH
-
- set testFH2 [open IOTEST2.TMP r]
- set testData2 [read $testFH2]
- close $testFH2
-
- list [expr [file size IOTEST2.TMP] == $copySize] \
- [string compare $testData $testData2]
- } 0 {1 0}
-
- catch {unset testData testData2}
- }
-
- set copySize [expr $testFileSize*2]
-
- Test filecmds-3.7 {copyfile tests} {
- set testFH [open IOTEST.TMP r]
- set testFH2 [open IOTEST2.TMP w]
- set stat [catch {copyfile -bytes $copySize $testFH $testFH2} msg]
- close $testFH
- close $testFH2
- list $stat $msg
- } 0 [list 1 \
- "premature EOF, $copySize bytes expected, $testFileSize bytes actually read"]
-
- Test filecmds-3.7 {copyfile tests} {
- set testFH [open IOTEST.TMP r]
- set testFH2 [open IOTEST2.TMP w]
- set stat [catch {copyfile -maxbytes $copySize $testFH $testFH2} msg]
- close $testFH
- close $testFH2
- list $stat $msg
- } 0 [list 0 $testFileSize]
-
- pipe readPF writePF
-
- flush stdout ;# Not going to exec, must clean up the buffers.
- flush stderr
- set sonPid [fork]
-
- if {$sonPid == 0} {
- for {set cnt 0} {$cnt < 50} {incr cnt} {
- Test filecmds-4.1 {pipe tests} {
- if {![gets $readPF msgBuf]} {
- set msgBuf "Premature eof on pipe"
- }
- set msgBuf
- } 0 [GenRec $cnt]
- }
- close $readPF
- exit 0
- }
-
- for {set cnt 0} {$cnt < 50} {incr cnt} {
- puts $writePF [GenRec $cnt]
- }
- flush $writePF
- Test filecmds-4.2 {pipe tests} {
- wait $sonPid
- } 0 "$sonPid EXIT 0"
-
- close $readPF
- close $writePF
-
- unlink -nocomplain {IOTEST.TMP IOTEST2.TMP IOTEST3.TMP}
-
-
-